<?php
/* -----------------------------------------------------------------
* 	ID:						$Id: product_info.php 6 2011-02-18 20:17:02Z akausch $
* 	Letzter Stand:			$Revision: 6 $
* 	zuletzt geändert von: 	$Author: akausch $
* 	Datum:					$Date: 2011-02-18 21:17:02 +0100 (Fr, 18. Feb 2011) $
*
* 	commerce:SEO by Webdesign Erfurt
* 	http://www.commerce-seo.de
*
* 	Copyright (c) since 2010 commerce:SEO
* ------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* --------------------------------------------------------------- */

require_once (DIR_FS_INC.'xtc_check_categories_status.inc.php');
require_once (DIR_FS_INC.'xtc_get_products_mo_images.inc.php');
require_once (DIR_FS_INC.'xtc_get_vpe_name.inc.php');
require_once (DIR_FS_INC.'get_cross_sell_name.inc.php');

$info_smarty = new Smarty;
if ($mobile_template == 'False') {
	$info_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
} else {
	$info_smarty->assign('tpl_path', 'templates/'.CURRENT_MOBILE_TEMPLATE.'/');
}

$group_check = '';
$info_smarty->assign('INFO_GALLERY', PRODUCT_INFO_GALLERY);
$info_smarty->assign('INFO_GALLERY_SLIDE', PRODUCT_INFO_GALLERY_SLIDE);

if (!is_object($product) || !$product->isProduct()) {
	$error = TEXT_PRODUCT_NOT_FOUND;
	include(DIR_WS_MODULES.FILENAME_ERROR_HANDLER);

} else {
	if (ACTIVATE_NAVIGATOR == 'true')
		include (DIR_WS_MODULES.'product_navigator.php');

	xtDBquery("update ".TABLE_PRODUCTS_DESCRIPTION." set products_viewed = products_viewed+1 where products_id = '".$product->data['products_id']."' and language_id = '".$_SESSION['languages_id']."'");

	$products_price = $xtPrice->xtcGetPrice($product->data['products_id'], $format = true, 1, $product->data['products_tax_class_id'], $product->data['products_price'], 1, '','info');
	$products_price_j = $xtPrice->xtcGetPrice($product->data['products_id'], $format = false, 1, $product->data['products_tax_class_id'], $product->data['products_price'], 1, '','info');
	$products_price_j = number_format($products_price_j,2);
	if(PRICE_AS_IMAGE == 'true') {
		$price = $products_price;
	} else {
		$price = $products_price['formated'];
	}
	
	if($_SESSION['customers_status']['customers_status_show_price'] != '0' && ALLOW_ADD_TO_CART == 'true') {
		if ($_SESSION['customers_status']['customers_fsk18'] == '1') {
			if ($product->data['products_fsk18'] == '0') {
				$info_smarty->assign('ADD_QTY', xtc_draw_input_field('products_qty', '1', 'size="3" class="products_qty" title="'.WCAG_QTY.'"').' '.xtc_draw_hidden_field('products_id', $product->data['products_id']));
				$info_smarty->assign('ADD_CART_BUTTON', xtc_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART));
				if(PRODUCT_DETAILS_WISHLIST == 'true') {
					$info_smarty->assign('ADD_WISHLIST_BUTTON', xtc_image_submit('button_to_wish_list.gif', WISHLIST,' onclick="document.cart_quantity.submit_target.value=\'wishlist\';"'));
				}
			}
		} else {
			$info_smarty->assign('ADD_QTY', xtc_draw_input_field('products_qty', '1', 'size="3" class="products_qty" title="'.WCAG_QTY.'"').' '.xtc_draw_hidden_field('products_id', $product->data['products_id']));
			$info_smarty->assign('ADD_CART_BUTTON', xtc_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART,' onclick="document.cart_quantity.submit_target.value=\'cart\';"').' '.xtc_draw_hidden_field('products_id', $product->data['products_id']));
			if(PRODUCT_DETAILS_WISHLIST == 'true') {
				$info_smarty->assign('ADD_WISHLIST_BUTTON', '<a href="'.xtc_href_link(FILENAME_PRODUCT_INFO,'products_id='.$product->data['products_id'].'&action=wishlist').'" rel="nofollow">'.xtc_image_button('button_to_wish_list.gif', WISHLIST).'</a>');
			}
		}
	}

	if ($product->data['products_fsk18'] == '1')
		$info_smarty->assign('PRODUCTS_FSK18', 'true');
	
	if (ACTIVATE_SHIPPING_STATUS == 'true') {
		$info_smarty->assign('SHIPPING_NAME', $main->getShippingStatusName($product->data['products_shippingtime']));
		$info_smarty->assign('SHIPPING_IMAGE', $main->getShippingStatusImage($product->data['products_shippingtime']));
	}
	$nuprice = number_format($products_price['plain'],2);
	$nuprice = str_replace(",", "", $nuprice);
	$nuprice = str_replace(".", "", $nuprice);
	$info_smarty->assign('CURRENCY', $_SESSION['currency']);
	$info_smarty->assign('LEFT', $xtPrice->currencies[$_SESSION['currency']]['symbol_left']);
	$info_smarty->assign('RIGHT', $xtPrice->currencies[$_SESSION['currency']]['symbol_right']);
	$info_smarty->assign('DECIMAL', $xtPrice->currencies[$_SESSION['currency']]['decimal_point']);
	$info_smarty->assign('THOUSAND', $xtPrice->currencies[$_SESSION['currency']]['thousands_point']);
	$info_smarty->assign('DECIMALS', $xtPrice->currencies[$_SESSION['currency']]['decimal_places']);
	if(PRICE_AS_IMAGE == 'true') {
		$nuprice = $products_price_j;
		$nuprice = str_replace(",", "", $nuprice);
		$nuprice = str_replace(".", "", $nuprice);
		$info_smarty->assign('PRODUCTS_NUPRICE', $nuprice);
	} else {
		$info_smarty->assign('PRODUCTS_NUPRICE', $nuprice);
	}	
	$info_smarty->assign('FORM_ACTION', xtc_draw_form('cart_quantity', xtc_href_link(FILENAME_PRODUCT_INFO, xtc_get_all_get_params(array('action')) . 'action=add_product'),'post', 'name="cart_quantity"').xtc_draw_hidden_field('submit_target','cart'));
	$info_smarty->assign('JAVASCRIPT_FORM_ACTION', '<script> function onsubmitform(){ document.cart_quantity.action ="'.xtc_href_link(FILENAME_PRODUCT_INFO, xtc_get_all_get_params(array('action'))) . 'action=add_product"; return true;} </script>');
	$info_smarty->assign('FORM_END', '</form>');
	
	$info_smarty->assign('PRODUCTS_PRICE', $price);
	$products_price = $xtPrice->xtcGetPrice($product->data['products_id'], false, 0, $product->data['products_tax_class_id'], $product->data['products_price']);
	if(PRODUCT_DETAILS_VPE == 'true') {
		if ($product->data['products_vpe_status'] == 1 && $product->data['products_vpe_value'] != 0.0 && $products_price > 0)
			$info_smarty->assign('PRODUCTS_VPE', $xtPrice->xtcFormat($products_price * (1 / $product->data['products_vpe_value']), true).TXT_PER.xtc_get_vpe_name($product->data['products_vpe']));
	}
	
	$info_smarty->assign('PRODUCTS_ID', $product->data['products_id']);
	$info_smarty->assign('PRODUCTS_NAME', $product->data['products_name']);
	if ($_SESSION['customers_status']['customers_status_show_price'] != 0) {
		$tax_rate = $xtPrice->TAX[$product->data['products_tax_class_id']];				
		$tax_info = $main->getTaxInfo($tax_rate);
		$info_smarty->assign('PRODUCTS_TAX_INFO', $tax_info);
		$info_smarty->assign('PRODUCTS_SHIPPING_LINK',$main->getShippingLink());
	}
	
	if (PRODUCT_DETAILS_STOCK == 'true') {
		require_once(DIR_FS_INC.'cseo_get_stock_img.inc.php');
		$info_smarty->assign('PRODUCTS_STOCK_IMG', cseo_get_stock_img($product->data['products_quantity']));
	}	
	
	if (PRODUCT_DETAILS_MODELLNR == 'true') {
		$info_smarty->assign('PRODUCTS_MODEL', $product->data['products_model']);
	}
	if (PRODUCT_DETAILS_MANUFACTURERS_MODELLNR == 'true') {
		$info_smarty->assign('PRODUCTS_MANUFACTURERS_MODEL', $product->data['products_manufacturers_model']);
	}	
	if (PRODUCT_DETAILS_EAN == 'true') {
		$info_smarty->assign('PRODUCTS_EAN', $product->data['products_ean']);
	}

	$info_smarty->assign('PRODUCTS_QUANTITY', $product->data['products_quantity']);

	if (PRODUCT_DETAILS_WEIGHT == 'true') {
		$info_smarty->assign('PRODUCTS_WEIGHT', $product->data['products_weight']);
	}
	$info_smarty->assign('PRODUCTS_STATUS', $product->data['products_status']);
	$info_smarty->assign('PRODUCTS_ORDERED', $product->data['products_ordered']);
	
	if (PRODUCT_DETAILS_TAGS == 'true') {
		$info_smarty->assign('PRODUCTS_TAGS', $product->getTagCloud());
	}
	
	if (PRODUCT_DETAILS_PRINT == 'true') {
		$info_smarty->assign('PRODUCTS_PRINT', '<a href="javascript:void(0)" onclick="javascript:window.open(\''.xtc_href_link(FILENAME_PRINT_PRODUCT_INFO, 'products_id='.$product->data['products_id']).'\', \'popup\', \'toolbar=0, width=640, height=600\')">'.xtc_image_button('print.gif',IMAGE_BUTTON_PRINT).'</a>');
	}
	
	if(!empty($product->data['products_movie_youtube_id']) || !empty($product->data['products_movie_on_server']) || !empty($product->data['products_movie_embeded_code'])) {
		
		$flash = '<script type="text/javascript"><!--'."\n".'jQuery(document).ready(function() {'."\n";
		
		if(!empty($product->data['products_movie_youtube_id']))
			$flash .= 'jQuery.jYoutube(\''.$product->data['products_movie_youtube_id'].'\', \'small\');'."\n";	
								
		$flash .= 'jQuery("a#swf_video").fancybox({ '."\n";
		
		if(!empty($product->data['products_movie_on_server']) || !empty($product->data['products_movie_embeded_code']))
			$flash .= 'onStart:function(){'."\n".'jQuery("#div_video").show();},'."\n".'onCleanup:function(){'."\n".'jQuery("#div_video").hide();},'."\n";
			
		$flash .= '\'titleShow\':\'false\','."\n".
				'\'transitionIn\':\'elastic\','."\n".
				'\'transitionOut\':\'elastic\','."\n".
				'\'frameWidth\':'.$product->data['products_movie_width'].','."\n".
				'\'frameHeight\':'.$product->data['products_movie_height'];
		
		if(!empty($product->data['products_movie_youtube_id']))
			$flash .= "\n".',\'type\' : \'swf\','."\n".'\'swf\' : {\'wmode\':\'transparent\',\'allowfullscreen\':\'true\'}';
		
		$flash .=	"\n".'});';
		
		if(!empty($product->data['products_movie_on_server']))
			$flash .= "\n".'swfobject.embedSWF("'.DIR_WS_CATALOG_MOVIES.$product->data['products_movie_on_server'].'", "embeded_video", "'.$product->data['products_movie_width'].'", "'.$product->data['products_movie_height'].'", "9.0.0");';
		
		$flash .= '});'."\n".'//-->'."\n".'</script>'."\n";
		
		if(!empty($product->data['products_movie_youtube_id'])) {
			$flash .= '<div id="youtube_img"></div>'."\n";
			$href = 'http://www.youtube-nocookie.com/v/'.$product->data['products_movie_youtube_id'].'&hl=de_DE&fs=1';
		} else
			$href = '#div_video';
		
		$flash .= '<a id="swf_video" href="'.$href.'">'."\n".'
						<span class="css_img_button">Video ansehen</span>'."\n".'
					</a>'."\n";
		if(!empty($product->data['products_movie_on_server']))
			$div = '<div id="embeded_video"></div>';
		elseif(!empty($product->data['products_movie_embeded_code']))
			$div = $product->data['products_movie_embeded_code'];
		
		$flash .= '<div id="div_video" class="dn">'."\n".$div."\n".'</div>'."\n";
	}
	
	$info_smarty->assign('PRODUCTS_FLASH', $flash);
	$info_smarty->assign('TREEPODIA_VIDEO', xtc_image_button('print.gif',IMAGE_BUTTON_TREEPODIA));
	if (PRODUCT_DETAILS_TAB_DESCRIPTION == 'true') {
	$info_smarty->assign('PRODUCTS_DESCRIPTION', $product->data['products_description']);
	}

	if (PRODUCT_DETAILS_TAB_PRODUCT == 'true') {
	$info_smarty->assign('PRODUCTS_DESCRIPTION_PRODUCT', $product->data['products_zusatz_description']);
	}

	if (PRODUCT_DETAILS_TAB_ADD == 'true') {
		if (GROUP_CHECK == 'true') {
			$group_check = "and group_ids LIKE '%c_".$_SESSION['customers_status']['customers_status_id']."_group%'";
		}
		if (PRODUCT_DETAILS_TAB_ADD_CONTENT_GROUP_ID != '') {
			$product_details_tab_add_query = xtDBquery("SELECT
								 content_id,
								 content_title,
								 content_heading,
								 content_text,
								 content_file
								 FROM ".TABLE_CONTENT_MANAGER."
								 WHERE content_group='".(int) PRODUCT_DETAILS_TAB_ADD_CONTENT_GROUP_ID."' ".$group_check."
								 AND languages_id='".(int) $_SESSION['languages_id']."'");
			$product_details_tab_add_data = xtc_db_fetch_array($product_details_tab_add_query);	

				if($product_details_tab_add_data['content_file'] != '') {
					ob_start();
					if (strpos($product_details_tab_add_data['content_file'], '.txt'))
						echo '<pre>';
						
					include (DIR_FS_CATALOG.'media/content/'.$product_details_tab_add_data['content_file']);
						
					if (strpos($product_details_tab_add_data['content_file'], '.txt'))
						echo '</pre>';
						
					$product_details_add_data = ob_get_contents();
					ob_end_clean();
				} else {
					$product_details_add_data = $product_details_tab_add_data['content_text'];
				}
			$info_smarty->assign('PRODUCTS_DESCRIPTION_ADD', $product_details_add_data);
		}
	}
	
	if(!empty($product->data['products_image'])) {
		$info_smarty->assign('img_name', $product->data['products_image']);
		$info_smarty->assign('img_nr', '1');
		$info_smarty->assign('img_path_thumb', DIR_WS_THUMBNAIL_IMAGES.$product->data['products_image']);
		$info_smarty->assign('img_path_info', DIR_WS_INFO_IMAGES.$product->data['products_image']);
		$info_smarty->assign('img_path_popup', DIR_WS_POPUP_IMAGES.$product->data['products_image']);
		$info_smarty->assign('img_dimension', cseo_get_img_size(DIR_WS_INFO_IMAGES.$product->data['products_image']));
		$info_smarty->assign('img_path_org', DIR_WS_ORIGINAL_IMAGES.$product->data['products_image']);
		$info_smarty->assign('img_alt', ($product->data['products_img_alt']!='')?$product->data['products_img_alt']:$product->data['products_name']);
		$js_img = '\''.DIR_WS_POPUP_IMAGES.$product->data['products_image'].'\'';
		$js_title = '\''.$product->data['products_name'].'\'';

		$products_mo_images_query = xtDBquery("SELECT
													image_id, image_nr, image_name, alt_langID_".$_SESSION['languages_id']."
												FROM
													products_images
												WHERE
													products_id = '" . $product->data['products_id'] ."'
												ORDER BY
													image_nr");

		if(xtc_db_num_rows($products_mo_images_query, true) > 0) {
			$images = array();
			if($product->data['products_image'] != '') {
				$images[] = array(	'name' => $product->data['products_image'],
									'nr' => '1',
									'dimension' => cseo_get_img_size(DIR_WS_INFO_IMAGES.$product->data['products_image']),
									'path_thumb' => DIR_WS_THUMBNAIL_IMAGES.$product->data['products_image'],
									'path_info' => DIR_WS_INFO_IMAGES.$product->data['products_image'],
									'path_popup' => DIR_WS_POPUP_IMAGES.$product->data['products_image'],
									'path_org' => DIR_WS_ORIGINAL_IMAGES.$product->data['products_image'],
									'alt' => ($product->data['products_img_alt']!=''?$product->data['products_img_alt']:$product->data['products_name']));
			}

			while ($img = xtc_db_fetch_array($products_mo_images_query,true)) {
				$js_img .= ',\''.DIR_WS_POPUP_IMAGES.$img['image_name'].'\'';
				$js_title .= ',\''.(!empty($img['alt_langID_'.$_SESSION['languages_id']]) ? $img['alt_langID_'.$_SESSION['languages_id']]:$product->data['products_name']).'\'';
				$more_images[] = array(	'name' => $img['image_name'],
									'nr' => ($img['image_nr'] + 1),
									'dimension' => cseo_get_img_size(DIR_WS_INFO_THUMBNAIL_IMAGES.$img['image_name']),
									'path_thumb' => DIR_WS_THUMBNAIL_IMAGES.$img['image_name'],
									'path_info' => DIR_WS_INFO_IMAGES.$img['image_name'],
									'path_popup' => DIR_WS_POPUP_IMAGES.$img['image_name'],
									'path_org' => DIR_WS_ORIGINAL_IMAGES.$img['image_name'],
									'alt' => ($img['alt_langID_'.$_SESSION['languages_id']]!='')?$img['alt_langID_'.$_SESSION['languages_id']]:$product->data['products_name']);
			}
		}
		$info_smarty->assign('js_img', $js_img);
		$info_smarty->assign('js_title', $js_title);
		if(is_array($more_images))
			$info_smarty->assign('images', $more_images);
		else
			$info_smarty->assign('images', $images);
	}
	
	$discount = 0.00;
	if ($_SESSION['customers_status']['customers_status_public'] == 1 && $_SESSION['customers_status']['customers_status_discount'] != '0.00') {
		$discount = $_SESSION['customers_status']['customers_status_discount'];
		if ($product->data['products_discount_allowed'] < $_SESSION['customers_status']['customers_status_discount'])
			$discount = $product->data['products_discount_allowed'];
		if ($discount != '0.00')
			$info_smarty->assign('PRODUCTS_DISCOUNT', $discount.'%');
	}
	
	include (DIR_WS_MODULES.'product_attributes.php');
	$msg = $_GET['msg'];
	
	if (PRODUCT_DETAILS_TAB_REVIEWS == 'true') {
		if($_SESSION['customers_status']['customers_status_read_reviews'] != 0)
			include (DIR_WS_MODULES.'product_reviews.php');
	}
	if (PRODUCT_DETAILS_ASKQUESTION == 'true') {
		include (DIR_WS_MODULES.'product_ask_a_question.php');	
	}		
	if (PRODUCT_DETAILS_TAB_PARAMETERS == 'true') {
		include (DIR_WS_MODULES.'product_parameters.php');
	}

	if (xtc_not_null($product->data['products_url']))
		$info_smarty->assign('PRODUCTS_URL', sprintf(TEXT_MORE_INFORMATION, xtc_href_link(FILENAME_REDIRECT, 'action=product&id='.$product->data['products_id'], 'NONSSL', true, false)));

	if ($product->data['products_date_available'] > date('Y-m-d H:i:s'))
		$info_smarty->assign('PRODUCTS_DATE_AVIABLE', sprintf(TEXT_DATE_AVAILABLE, xtc_date_long($product->data['products_date_available'])));
	else {
		if ($product->data['products_date_added'] != '0000-00-00 00:00:00')
			$info_smarty->assign('PRODUCTS_ADDED', sprintf(TEXT_DATE_ADDED, xtc_date_long($product->data['products_date_added'])));
	}

	if ($_SESSION['customers_status']['customers_status_graduated_prices'] == 1)
		include (DIR_WS_MODULES.FILENAME_GRADUATED_PRICE);

	if (PRODUCT_DETAILS_TAB_MEDIA == 'true') {
		include (DIR_WS_MODULES.FILENAME_PRODUCTS_MEDIA);
	}
	if (PRODUCT_DETAILS_TAB_ALSO_PURCHASED == 'true') {
		include (DIR_WS_MODULES.FILENAME_ALSO_PURCHASED_PRODUCTS);
	}
	if (PRODUCT_DETAILS_TAB_CROSS_SELLING == 'true') {
		include (DIR_WS_MODULES.FILENAME_CROSS_SELLING);
	}
	if (PRODUCT_DETAILS_RELATED_CAT == 'true') {
		include (DIR_WS_MODULES.FILENAME_PRODUCTS_RELATED_CAT);	
	}

	if (PRODUCT_DETAILS_SOCIAL == 'true') {
		$info_smarty->assign('PRODUCTS_SOCIAL', 'true');
	}
	
	if ($product->data['product_template'] == '' or $product->data['product_template'] == 'default') {
		$files = array ();
		#Mobile Abfrage
		if ($mobile_template == 'False') {
			if ($dir = opendir(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/module/product_info/')) {
					while ($file = readdir($dir)) {
						if (is_file(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/module/product_info/'.$file) and ($file != "index.html") and (substr($file, 0, 1) !="."))
							$files[] = array ('id' => $file, 'text' => $file);
					}
					closedir($dir);
				}
		} else {
			if ($dir = opendir(DIR_FS_CATALOG.'templates/'.CURRENT_MOBILE_TEMPLATE.'/module/product_info/')) {
					while ($file = readdir($dir)) {
						if (is_file(DIR_FS_CATALOG.'templates/'.CURRENT_MOBILE_TEMPLATE.'/module/product_info/'.$file) and ($file != "index.html") and (substr($file, 0, 1) !="."))
							$files[] = array ('id' => $file, 'text' => $file);
					}
					closedir($dir);
				}
		}
		#Mobile End


		$product->data['product_template'] = $files[0]['id'];
	}

	$i = count($_SESSION['tracking']['products_history']);
	if ($i > 6) {
		array_shift($_SESSION['tracking']['products_history']);
		$_SESSION['tracking']['products_history'][6] = $product->data['products_id'];
		$_SESSION['tracking']['products_history'] = array_unique($_SESSION['tracking']['products_history']);
	} else {
		$_SESSION['tracking']['products_history'][$i] = $product->data['products_id'];
		$_SESSION['tracking']['products_history'] = array_unique($_SESSION['tracking']['products_history']);
	}
	
	$info_smarty->assign('language', $_SESSION['language']);
	if (!CacheCheck()) {
		$info_smarty->caching = 0;
		if ($mobile_template == 'False') {
			$product_info = $info_smarty->fetch(CURRENT_TEMPLATE.'/module/product_info/'.$product->data['product_template']);
		} else {
			$product_info = $info_smarty->fetch(CURRENT_MOBILE_TEMPLATE.'/module/product_info/'.$product->data['product_template']);
		}		
	} else {
		$info_smarty->caching = 1;
		$info_smarty->cache_lifetime = CACHE_LIFETIME;
		$info_smarty->cache_modified_check = CACHE_CHECK;
		$cache_id = $product->data['products_id'].$_SESSION['language'].$_SESSION['customers_status']['customers_status_name'].$_SESSION['currency'];
		if ($mobile_template == 'False') {
			$product_info = $info_smarty->fetch(CURRENT_TEMPLATE.'/module/product_info/'.$product->data['product_template'], $cache_id);
		} else {
			$product_info = $info_smarty->fetch(CURRENT_MOBILE_TEMPLATE.'/module/product_info/'.$product->data['product_template'], $cache_id);
		}	
	}
}
$smarty->assign('main_content', $product_info);
?>